<template>
	<view>
		<el-upload class="upload-demo" :on-success="handleAvatarSuccess"  :action="action"
			:headers="headers" :before-upload="handleFileChange" :show-file-list="false" style="width: 100%;">
			<el-button class="blue_btn" style="width: 100%;background: #2F6CBC;border: 1px solid #2F6CBC;"
				type="primary">上传体检报告</el-button>
		</el-upload>
	</view>
</template>
<script>
	import {
		URL_IP_HOST,
		URL_PREFIX
	} from '@/util/constant.js'
	import {
		parserResume
	} from "@/api/my.js"
	export default {
		data() {
			var userInfoData_ = uni.getStorageSync("userInfoData_")
			return {
				headers: {
					"Authorization": `Bearer ${userInfoData_ ? userInfoData_.access_token : ""}`,
					"clientid": userInfoData_ ? userInfoData_.client_id : "eeb9377d4b6debbc0a6e8756bbbbb4c7"
				},
				action: URL_IP_HOST+"/application/oss/upload",
			};
		},
		methods: {
			handleAvatarSuccess(res, file) {
				console.log("文件上传成功：", res, file);
				this.$emit("uploadImageClick",res.data.ossId)
			},
			handleFileChange(rawFile) {
				console.log(rawFile);
				// if (rawFile.type !== 'application/msword' &&rawFile.type !== 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' &&rawFile.type !== 'application/pdf' && rawFile.type !== 'image/jpg' && rawFile.type !== 'image/png') {
				// 	this.$message({
				// 		message: '格式有误! 仅支持jpg、png、doc、docx、pdf格式!',
				// 		type: 'error',
				// 		offset: 0.1
				// 	});
				// 	return false
				// }
				if (rawFile.type !== 'image/jpeg' && rawFile.type !== 'application/msword' && rawFile.type !== 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' && rawFile.type !== 'application/pdf' && rawFile.type !== 'image/jpg' && rawFile.type !== 'image/png') {
					this.$message({
						message: '格式有误! 仅支持jpg、png、doc、docx、pdf格式!',
						type: 'error',
						offset: 0.1
					});
					return false
				}
			}
		}
	}
</script>
<style lang="scss" scoped>
	::v-deep .upload-demo{
		.el-upload{
			width: 100%;
		}
	}
	
	.blue_btn {
		background: #2F6CBC;
		border: 1px solid #2F6CBC;
	}
</style>
